//
//  YXJCollectionCell.m
//  Piece
//
//  Created by dllo on 16/6/7.
//  Copyright © 2016年 Northeast Dianli University. All rights reserved.
//

#import "YXJCollectionCell.h"
#import "UIImageView+WebCache.h"

@implementation YXJCollectionCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.tableView = [[YXJTableView alloc] init];
        [self.contentView addSubview:_tableView];
        
        __weak YXJCollectionCell *cC = self;
        _tableView.clickBlock = ^()
        {
            cC.clickBlock();
        };

        
        __weak YXJCollectionCell *cell = self;
        cell.tableView.myBlock = ^(NSInteger number, NSInteger pageID)
        {
            _block(number, pageID);
        };

        
    }
    return self;
}

-(void)layoutSubviews
{
    self.tableView.frame = self.contentView.bounds;
}

-(void)setModel:(YXJMusicModel *)model
{
    if (_model != model) {
        _model = model;
    }
    [self.tableView.photoImageView sd_setImageWithURL:[NSURL URLWithString:model.cover] placeholderImage:[UIImage imageNamed:@"music_placeholder"]];
    [self.tableView.contentView.userImageView sd_setImageWithURL:[NSURL URLWithString:model.authorModel.web_url]];
    self.tableView.contentView.realName.text = model.authorModel.user_name;
    self.tableView.contentView.nickName.text = model.authorModel.desc;
    self.tableView.contentView.musicName.text = model.title;
    self.tableView.contentView.dateLabel.text = [self changeFormString:model.maketime];
    self.tableView.model = model;
    
}

- (NSString *)changeFormString:(NSString *)string
{
    NSDateFormatter *inputFormatter = [[NSDateFormatter alloc] init];
    [inputFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]];
    [inputFormatter setDateFormat:@"yy-MM-dd HH:mm:ss"];//yyyyMMddHHmmss
    
    NSDate *inputDate = [inputFormatter dateFromString:string];
    
    NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
    [outputFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]];
    [outputFormatter setDateFormat:@"MMM.dd.yyyy"];
    
    NSString *outputDate = [outputFormatter stringFromDate:inputDate];
    return outputDate;
}



- (void)setDidSelected:(BOOL)didSelected
{
    if (didSelected == NO) {
        [self.tableView.contentView.playButton setImage:[UIImage imageNamed:@"pause_normal"] forState:UIControlStateNormal];
    }
    else
    {
        [self.tableView.contentView.playButton setImage:[UIImage imageNamed:@"play_normal"] forState:UIControlStateNormal];
    }
}


-(void)setContentDataSource:(NSMutableArray *)contentDataSource
{
    if (_contentDataSource != contentDataSource) {
        _contentDataSource = contentDataSource;
        self.tableView.contentDataSource = contentDataSource;
    }
}

-(void)setLikeMusciDataSource:(NSMutableArray *)likeMusciDataSource
{
    if (_likeMusciDataSource != likeMusciDataSource) {
        _likeMusciDataSource = likeMusciDataSource;
        self.tableView.likeMusicDataSource = likeMusciDataSource;
    }
}

@end
